package cn.sdormitory.controller;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.schoolActivity.Req.SchoolActivityParamReq;
import cn.sdormitory.schoolActivity.Req.SchoolActivityReq;
import cn.sdormitory.schoolActivity.entity.SchoolActivity;
import cn.sdormitory.service.AppActivityService;
import cn.sdormitory.smartdor.vo.SdStudentLeaveVo;
import cn.sdormitory.workflow.entity.ViolationApply;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;

/**
 * @className: AppActivieController
 * @author: Alex
 * @date: 2024/12/16
 **/
@RestController
@RequestMapping("/app/activity")
public class AppActivityController {
	
	@Resource
	private AppActivityService appActivityService;
	
	@ApiOperation("createActivity => 新增学校活动")
	@PostMapping(value = "/createActivity")
	public CommonResult<Integer> createOrUpdateActivity(@RequestBody SchoolActivityReq schoolActivityReq) {
		int num = appActivityService.createOrUpdateActivity(schoolActivityReq);
		if (num > 0) {
			return CommonResult.success();
		}
		return CommonResult.failed();
		
	}
	
	@ApiOperation("deleteById => 根据id删除活动")
	@DeleteMapping("/deleteById/{id}")
	public CommonResult<Boolean> deleteActivityById(@PathVariable long id){
		boolean result = appActivityService.deleteById(id);
		if (result) {
			return CommonResult.success(result);
		}
		return CommonResult.failed();
	}
	
	@ApiOperation("getActivityDetailById => 根据id获取活动详情")
	@GetMapping("getActivityDetailById/{id}")
	public CommonResult<SchoolActivity> getActivityDetailById(@PathVariable Long id) {
		SchoolActivity schoolActivity =  appActivityService.getActivityDetailById(id);
		return CommonResult.success(schoolActivity);
	}
	
	@ApiOperation("pageList => 分页获取活动列表")
	@PostMapping("/pageList")
	public CommonResult<CommonPage<SchoolActivity>> pageList(@RequestBody SchoolActivityParamReq vo){
		IPage<SchoolActivity> page = appActivityService.pageList(vo);
		return CommonResult.success(CommonPage.restPage(page));
	}
}
